C#########################################################
C This file is part of OpenAD released under the LGPL.   #
C The full COPYRIGHT notice can be found in the top      #
C level directory of the OpenAD distribution             #
C#########################################################
        SUBROUTINE OpenAD_MASKER(N, M, THCK, NMSB, MASK, COUNT)
          use OAD_tape
          use OAD_rev

C original arguments get inserted before version
C         ! and declared here together with all local variables
C         ! generated by xaifBooster

        use OAD_active
        INTEGER N
        INTEGER M
        REAL THCK(1 : N, 1 : M)
        REAL NMSB(1 : N, 1 : M)
        INTEGER MASK(1 : N, 1 : M)
        INTEGER COUNT
C
C       **** Local Variables and Functions ****
C
        INTEGER I
        INTEGER J


          integer iaddr
          external iaddr
C
C       **** Statements ****
C
        COUNT = 1
        MASK(1 : N, 1 : M) = 0
        DO I = 2, (N +(-1)), 1
          DO J = 2, (M +(-1)), 1
            IF((NMSB(I, J) .GT. 0.0D00) .OR. ANY(THCK(I +(-1) : I + 1, J
     + +(-1) : J + 1) .ne. 0.0D00)) THEN
              MASK(I, J) = COUNT
              COUNT = (COUNT + 1)
            ENDIF
            if (oad_dt_sz.lt.oad_dt_ptr) call oad_dt_grow()
            oad_dt(oad_dt_ptr) = NMSB(I,J)
            oad_dt_ptr = oad_dt_ptr+1
            if (oad_dt_sz.lt.oad_dt_ptr+(size(THCK(I+(-1):I+1,J+(-1):J+1
     +),1)*size(THCK(I+(-1):I+1,J+(-1):J+1),2))) call oad_dt_grow()
            oad_dt(oad_dt_ptr:) = reshape(THCK(I+(-1):I+1,J+(-1):J+1),(/
     +size(THCK(I+(-1):I+1,J+(-1):J+1),1)*size(THCK(I+(-1):I+1,J+(-1):J+
     +1),2)/))
            oad_dt_ptr = oad_dt_ptr+(size(THCK(I+(-1):I+1,J+(-1):J+1),1)
     +*size(THCK(I+(-1):I+1,J+(-1):J+1),2))
          END DO
        END DO
        if (oad_it_sz.lt.oad_it_ptr) call oad_it_grow()
        oad_it(oad_it_ptr) = N
        oad_it_ptr = oad_it_ptr+1
        if (oad_it_sz.lt.oad_it_ptr) call oad_it_grow()
        oad_it(oad_it_ptr) = M
        oad_it_ptr = oad_it_ptr+1
        COUNT = (COUNT +(-1))

         if (our_rev_mode%plain) then
C original function
          end if
          if (our_rev_mode%tape) then
C taping
          end if
          if (our_rev_mode%adjoint) then
C adjoint
          end if
        end subroutine OpenAD_MASKER
